<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入账号" id="txt">
    <input type="text" placeholder="请输入密码" id="pwd">
    <input type="button" value="点击" id="btn">

    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.0/mock-min.js"></script>
    <script>
        // localStorage.setItem('id', 'zhangsan');
        // localStorage.setItem('password', '123');

        let arr = [
            { 'id': 'zhangsan', 'password': '123' },
            { 'id': 'lisi', 'password': '456' },
        ];

        let result = JSON.stringify(arr); // 引用数据类型 -> 基本数据类型
        console.log(result, typeof result);

        localStorage.setItem('users', result);

        btn.onclick = function () {
            // 拿数据
            let getValue = localStorage.getItem('users');
            // 基本数据类型 getValue -> 引用数据类型
            let newArr = JSON.parse(getValue);
            let user = newArr.filter(item => item.id == txt.value && item.password == pwd.value)[0]; // undefined
            if (user) {
                console.log("欢迎");
            } else {
                console.log("查无此人");
            }


            // if (txt.value == localStorage.getItem('id') && pwd.value == localStorage.getItem('password')) {
            //     console.log("欢迎");
            // } else {
            //     console.log("查无此人");
            // }
        }


        // btn.onclick = function () {
        //     if (txt.value == localStorage.getItem('id') && pwd.value == localStorage.getItem('password')) {
        //         console.log("欢迎");
        //     } else {
        //         console.log("查无此人");
        //     }
        // }


        // let result = Mock.mock({
        //     "students|26": [{
        //         'id|+1': 1,
        //         'name': '@cname()',
        //         'age|20-38': 1,
        //         'gender|1': ['男', '女'],
        //         'score|37-100': 1
        //     }]
        // }).students;
        // // let arr = result.students;
        // console.log(result);
    </script>
</body>

</html>